define('apm/ui/grid/override_grid',['require','broada/wijmo/wijgrid/jquery.wijmo.wijgrid'],function(require) {
    
    require("broada/wijmo/wijgrid/jquery.wijmo.wijgrid");
    var wijgrid = wijmo.grid.wijgrid;

    //添加totalRows pageSize
    wijgrid.prototype._pagerSettings2PagerWidgetSettings = function() {

        return jQuery.extend({}, this.options.pagerSettings, {
            emptyString: '没有列表数据',
            previousPageText: '<',
            nextPageText: '>',
            mode: 'all',
            disabled: this.options.disabled,
            pageCount: this.pageCount(),
            totalRows: this.options.totalRows,
            pageSize: this.options.pageSize,
            pageIndex: this.options.pageIndex,
            pageIndexChanging: jQuery.proxy(this._onPagerWidgetPageIndexChanging, this),
            pageIndexChanged: jQuery.proxy(this._onPagerWidgetPageIndexChanged, this)
        })
    };

    var _decorateHeaderContent = wijmo.grid.c1field.prototype._decorateHeaderContent;
    wijmo.grid.c1field.prototype._decorateHeaderContent = function($container) {
        _decorateHeaderContent.apply(this, arguments);

        if (this.options.selectAll) {
            var me = this, wijgrid = this._owner(), $checkbox = $('<input type="checkbox" class="gird-checkbox-all" />').appendTo($container.children().first());
            
            var options = Ember.Object.extend({
                checkedAll: Ember.computed('data.local.@each._checked', function(key, value) {
                    var data = Ember.A(this.get('data.local'));

                    if (arguments.length > 1) {
                        data.forEach(function(item) {
                            Ember.set(item, '_checked', value);
                        });
                    } else {
                        return data.filterProperty('_checked', true).length == data.length;
                    }
                })
            }).create(this._owner().options);

            $checkbox.bind("click." + this.widgetName + '-check', function() {
                options.set('checkedAll', this.checked);
            });

            Ember.addObserver(options, "checkedAll", function() {
                $checkbox.prop('checked', options.get("checkedAll"));
            });
        }
    };

    wijmo.grid.c1field.prototype._onCheckClick = function (args){
        var grid = args.data._owner(), checked = args.target.checked;

        $checkbox = grid.element.find('.wijmo-wijgrid-datarow :checkbox');
        $checkbox.filter(function() {
            return this.checked != checked;
        }).trigger('click');
    };

    $.wijmo.registerWidget("c1field", wijmo.grid.c1field.prototype);
    $.wijmo.registerWidget("wijgrid", wijgrid.prototype);
});

define('apm/ui/grid/override_pager',['require','broada/wijmo/wijpager/jquery.wijmo.wijpager'],function(require) {
    require("broada/wijmo/wijpager/jquery.wijmo.wijpager");
    var wijpager = wijmo.pager.wijpager;

    //去了链接里的#
    wijpager.prototype._createPagerItem = function(e, t, r, i) {
        var n = jQuery,
            s, o = this.options.wijCSS,
            u = this,
            a = n("<li />").addClass("wijmo-wijpager-button " + o.cornerAll).attr({
                role: "tab",
                "aria-label": t,
                title: t
            });
        return e ? a.addClass(o.stateActive).attr("aria-selected", "true") : a.addClass(o.stateDefault).hover(function() {
            u.options.disabled || n(this).removeClass(o.stateDefault).addClass(o.stateHover)
        }, function() {
            u.options.disabled || n(this).removeClass(o.stateHover).addClass(o.stateDefault)
        }).bind("click." + this.widgetName, {
            newPageIndex: r - 1
        }, n.proxy(this._onClick, this)), e ? s = n("<span />") : s = i ? n("<span />").addClass(o.icon + " " + i) : n("<a/>").attr("href", "javascript:;"), s.text(t), a.append(s), a
    }

    //添加总记录提示
    wijpager.prototype._refresh = function() {
        var opts = this.options;

        this._validate();
        if(this.$ul) {
            this.$ul.remove();
        }
        this.element.append(this.$ul = $("<ul class=\"ui-list " + this.options.wijCSS.cornerAll + " " + this.options.wijCSS.content + " " + this.options.wijCSS.helperClearFix + "\" role=\"tablist\"></ul>"));
        
        if (opts.totalRows && opts.totalRows > 0) {
            switch((this.options.mode || "").toLowerCase()) {
                case "nextprevious":
                    this._createNextPrev(false);
                    break;
                case "nextpreviousfirstlast":
                    this._createNextPrev(true);
                    break;
                case "numeric":
                    this._createNumeric(false);
                    break;
                case "numericfirstlast":
                    this._createNumeric(true);
                    break;
                //
                case "all":
                    this._createPageAll()
                    break;
            }

            this.$p && this.$p.remove(), this.element.prepend(this.$p = $('<p class="ui-pager-left"></p>'));
            //this.$p.html('显示' + ((opts.pageSize * opts.pageIndex) + 1) + '-' + Math.min(opts.pageSize * (opts.pageIndex+1), opts.totalRows) + ' 共'+opts.totalRows+'条记录');
            this.$p.html('共 '+opts.totalRows+' 条');
        } else if (opts.totalRows === 0) {
            this.element.html('<p class="wijmo-wijgrid-nodata">'+opts.emptyString+'</p>');
        }
    }

    wijpager.prototype._createPageAll = function() {
        var o = this.options, currentPage = o.pageIndex + 1, startPageNumber = 1, endPageNumber = o.pageCount, i;
        var pager = {
            // 当前页的最大紧邻前置页数（不包括最前面的显示页数）
            preposePagesCount: 2,
            // 当前页的最大紧邻后置页数
            postposePagesCount: 2,
            // 第一个"..."前显示的页数
            firstPagesCount: 2,
            // 第二个"..."后显示的页数
            lastPagesCount: 1
        };

        (currentPage <= pager.postposePagesCount) && (pager.postposePagesCount += pager.preposePagesCount - currentPage + 1);
        this.$ul.append(this._createPagerItem(false, o.previousPageText, o.pageIndex, o.previousPageClass));

        if (currentPage <= pager.firstPagesCount + pager.preposePagesCount + 1) {
            for(var i = 1; i < currentPage; i++) {
                this.$ul.append(this._createPagerItem(false, i.toString(), i, ""));
            }
        } else {
            for(var i = 1; i<=pager.firstPagesCount; i++) {
                this.$ul.append(this._createPagerItem(false, i.toString(), i, ""));
            }
            
            this.$ul.append(this._createPagerItem(false, "...", '', ""));

            for(var i = currentPage - pager.preposePagesCount; i <= currentPage-1; i++) {
                this.$ul.append(this._createPagerItem(false, i.toString(), i, ""));
            }
        }
        
        // 当前页的页码展示
        this.$ul.append(this._createPagerItem(true, currentPage.toString(), currentPage, ""));
        
        // 当前页的后的页码展示
        if (currentPage >= endPageNumber - pager.lastPagesCount - pager.postposePagesCount) {
            for(var i = currentPage + 1; i <= endPageNumber; i++) {
                this.$ul.append(this._createPagerItem(false, i.toString(), i, ""));
            }
        } else {
            for(var i = currentPage+1; i <= currentPage + pager.postposePagesCount; i++) {
                this.$ul.append(this._createPagerItem(false, i.toString(), i, ""));
            }
            this.$ul.append(this._createPagerItem(false, "...", '', ""));
            for(var i = endPageNumber - pager.lastPagesCount + 1; i <= endPageNumber; i++) {
                this.$ul.append(this._createPagerItem(false, i.toString(), i, ""));
            }
        }

        this.$ul.append(this._createPagerItem(false, o.nextPageText, o.pageIndex + 2, o.nextPageClass));
        this._createGoPage();
    };

    /*
     * @todo 跳转至指定页码
    */
    wijpager.prototype._createGoPage = function() {
        var me = this, o = this.options, currentPage = o.pageIndex + 1;
        if (!this.$go) {
            //this.$go = $('<div class="ui-pager-go"><input type="text" class="ui-pager-input"/><a class="ui-pager-go-btn">跳转</a></div>').insertBefore(this.$ul);
            this.$go = $('<div class="ui-pager-go">跳至&nbsp;<input type="text" class="ui-pager-input"/><a class="ui-pager-go-btn">跳转</a>&nbsp;页</div>').insertBefore(this.$ul);
            var $input = this.$go.find('input'),
                $btn = this.$go.find('a');

            $input.on('keypress', function(e) {
                if (e.which == 13) {
                    $btn.trigger('click');
                }
                return e.which >= 48 && e.which <= 57;
            }).on('blur', function() {
                var value = $(this).val();

                if (value) {
                    value = parseInt(value);
                    value = value < 0 ? 1 : (value > o.pageCount ? o.pageCount : value);
                    $(this).val(value);
                }
            });

            $btn.on('click', function() {
                var page = $input.val();

                if (page && page != (o.pageIndex+1)) {
                    $.proxy(me._onClick, me)({
                        data: {
                            newPageIndex: page - 1
                        }
                    });
                }
            });
        }
    }

    $.wijmo.registerWidget("wijpager", wijpager.prototype);
})

define('apm/ui/grid',['require','broada/ui/grid', 'apm/ui/grid/override_grid', 'apm/ui/grid/override_pager'], function (require) {
    require('apm/ui/grid/override_grid');
    require('apm/ui/grid/override_pager');

    var Grid = require('broada/ui/grid');

    APM.ui.Grid = Grid.extend({

    });
    return Grid;
});